package com.zhuang.principle.liskov;

/**
 * @Classname Liskov
 * @Description 里氏代换原则错误示范
 * @Date 2021/3/15 13:58
 * @Created by dell
 */

public class Liskov {
    public static void main(String[] args) {
        A a = new A();
        System.out.println("11-3=" +a.fun1(11,3));
        System.out.println("11-8=" +a.fun1(11,8));

        System.out.println("===================");

        B b = new B();
        System.out.println("11-3="+b.fun1(11,3));
        System.out.println("1-8="+b.fun1(1,8));
        System.out.println("11+3+9="+b.fun2(11,3));
    }
}

class A{
    //返回两个数的差
    public int fun1(int num1,int num2){
        return num1-num2;
    }
}

//B类继承A 增加新功能，完成两个数相加，然后和9求和
class B extends A{
    @Override
    public int fun1(int a, int b) {
        return a+b;
    }

    public int fun2(int a, int b) {
        return fun1(a,b)+9;
    }
}
